package com.example.tliasmanagement.controller;

import com.example.tliasmanagement.dto.AddClazzDto;
import com.example.tliasmanagement.dto.ClazzListDto;
import com.example.tliasmanagement.dto.UpdateClazzDto;
import com.example.tliasmanagement.entity.Clazz;
import com.example.tliasmanagement.service.ClazzService;
import com.example.tliasmanagement.vo.ClazzListVo;
import com.example.tliasmanagement.vo.EmpVo;
import com.example.tliasmanagement.vo.PageBean;
import com.example.tliasmanagement.vo.Result2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    /* *
     * 班级列表分页查询
     *
     * */
    @GetMapping("/clazzs")
    public Result2<PageBean<ClazzListVo>> clazzs(ClazzListDto dto) {
        PageBean<ClazzListVo> pageBean = clazzService.clazzs(dto);
        return Result2.ok(pageBean);
    }

    /**
     * 新增班级
     */
    @PostMapping("/clazzs")
    public Result2 addClazz(@RequestBody AddClazzDto dto) {
        clazzService.addClazz(dto);
        return Result2.ok();
    }

    /**
     * 查询员工
     */
    @GetMapping("/emps/list")
    public Result2<List<EmpVo>> getName() {
        List<EmpVo> getnames = clazzService.getName();
        return Result2.ok(getnames);
    }

    /**
     * 删除班级
     */
    @DeleteMapping("/clazzs/{id}")
    public Result2 deleteById(@PathVariable Integer id) {
        clazzService.deleteById(id);

        return Result2.ok();
    }


    @GetMapping("/clazzs/{id}")
    public Result2<Clazz> getById(@PathVariable("id") Integer id) {
        Clazz clazz = clazzService.getById(id);
        return Result2.ok(clazz);
    }

    @PutMapping("/clazzs")
    public Result2 updateClazz(@RequestBody UpdateClazzDto dto) {
        clazzService.updateClazz(dto);
        return Result2.ok();
    }

}
